//
//  StateManager.cpp
//  Space shooting
//
//  Created by Raiden on 9/2/13.
//
//

#include "StateManager.h"
#include "Constants.h"
#include "SplashLayer.h"
#include "HomeLayer.h"
#include "Game.h"
#include "Level01Layer.h"
#include "TutorialLayer.h"
#include "SettingLayer.h"

static StateManager         *stageManager;

StateManager* StateManager::getInstance() {
    
    if(stageManager == NULL) {
        
        stageManager = new StateManager;
    }
    
    return stageManager;
}

bool StateManager::init() {
    
    m_layer = NULL;
    m_director = CCDirector::sharedDirector();
    m_scene = CCScene::create();    
    
    m_director->runWithScene(m_scene);
    
    return true;
}

void StateManager::switchScene(int state) {
    
    CCLayer *layer;
    
    switch (state) {
            
        case GAME_STATE_SPLASH:
            layer = new SplashLayer();
            break;
            
        case GAME_STATE_LOADING:
            
            break;
            
        case GAME_STATE_HOME:
            layer = new HomeLayer;
            break;
            
        case GAME_STATE_GAME:
            layer = new Level01Layer;
            Game::getInstance()->resetData();
            break;
            
        case GAME_STATE_TUT:
            layer = new TutorialLayer;
            break;
            
        case GAME_STATE_SETTING:
            layer = new SettingLayer;
            break;
            
        default:
            break;
    }
    
    if(m_layer != NULL) {
        m_scene->removeChild(m_layer);
    }
    
    m_scene->addChild(layer);    
    m_layer = layer;
    
    MainScene = layer;
    
}